/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.web.servlet;

import com.web.daoimpl.CourseDaoImpl;
import com.web.daoimpl.StudentDaoImpl;
import com.web.entity.Course;
import com.web.entity.Grade;
import com.web.entity.Stu_admin;
import com.web.service.Testdaoimpl;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author liqianru
 */
@WebServlet("/getallStu")
public class Admin_getallStudent extends HttpServlet {

    StudentDaoImpl service = new StudentDaoImpl();
    CourseDaoImpl service2 = new CourseDaoImpl();
    Testdaoimpl gradeservice = new Testdaoimpl();
    List<Grade> gradeList = new ArrayList<>();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String action = req.getParameter("action");
        HttpSession session = req.getSession(false);
        if (req.getParameter("action").equals("getall")) {
            List<Stu_admin> allStudent = service.getallStudent();
            session.setAttribute("allStu", allStudent);
            System.out.println(allStudent.size() + "" + allStudent.get(0).getSid());
            req.getRequestDispatcher("/admin_Student.jsp").forward(req, resp);
        }
        if (action.equals("getone")) {
            String sid = req.getParameter("sid");
            Stu_admin onestudent = service.getoneBysid(sid);
            req.setAttribute("onestudent", onestudent);
            session.setAttribute("admin_sid", sid);
            session.setAttribute("admin_classid", onestudent.getClassID());
            //
            List<Course> oneCourselist = new ArrayList<>();
            oneCourselist = service2.getoneSchedule((String) session.getAttribute("admin_classid"));
            req.setAttribute("oneCourselist", oneCourselist);
            //
            gradeList = gradeservice.getOneStudentgradeBysid(sid);
            //System.out.println(gradeList.size());
            req.setAttribute("gradelist", gradeList);
            req.getRequestDispatcher("/admin_Student_details.jsp").forward(req, resp);
        }
        if(action.equals("isrepeat")){
            int sid=Integer.valueOf(req.getParameter("sid"));
            int status=0;
            boolean isrepeat=service.isRepeatStudent(sid);
            //System.out.println(isrepeat);
            if(isrepeat){
                status=1;
                resp.getWriter().print(status);//1代表true
            }
            else{
                 resp.getWriter().print(status);//0代表false
            }
            
        }
    }

}
